package com.zone.vehicle.sdk.module.superapp.cloud;

import android.content.Context;

import com.zone.sdk.common.http.apimock.ApiMock;
import com.zone.sdk.common.http.base.BaseRequest;
import com.zone.sdk.common.http.base.Result;
import com.zone.sdk.common.http.callback.ResultCallBack;
import com.zone.sdk.module.account.CloudAccountServiceManager;
import com.zone.sdk.module.account.entity.CaptchaCertExchangeEntity;
import com.zone.sdk.module.account.entity.CaptchaGetEntity;
import com.zone.sdk.module.account.entity.CheckCaptchaEntity;
import com.zone.sdk.module.account.entity.LoginEntity;
import com.zone.sdk.module.account.entity.LoginStatusEntity;
import com.zone.sdk.module.account.entity.QrLoginEntity;
import com.zone.sdk.module.account.entity.QrLoginPollEntity;
import com.zone.sdk.module.account.entity.UploadEntity;
import com.zone.sdk.module.account.entity.UserInfoEntity;
import com.zone.sdk.module.account.request.CaptchaCertExchangeRequest;
import com.zone.sdk.module.account.request.CaptchaGetRequest;
import com.zone.sdk.module.account.request.CheckCaptchaRequest;
import com.zone.sdk.module.account.request.LoginRequest;
import com.zone.sdk.module.account.request.LogoutRequest;
import com.zone.sdk.module.account.request.QrLoginPollRequest;
import com.zone.sdk.module.account.request.QrLoginRequest;
import com.zone.sdk.module.account.request.RefreshTokenRequest;
import com.zone.sdk.module.account.request.UploadRequest;
import com.zone.sdk.module.account.request.UserInfoRequest;
import com.zone.sdk.module.account.response.CaptchaGetResponse;
import com.zone.sdk.module.appstore.CloudAppStoreServiceManager;
import com.zone.sdk.module.appstore.base.AppStoreResult;
import com.zone.sdk.module.appstore.entity.AppEntity;
import com.zone.sdk.module.appstore.request.AppsDetailRequest;
import com.zone.sdk.module.comment.CloudCommentServiceManager;
import com.zone.sdk.module.comment.base.CommentPage;
import com.zone.sdk.module.comment.entity.AppCommentScoreEntity;
import com.zone.sdk.module.comment.entity.CommentListEntity;
import com.zone.sdk.module.comment.entity.RecommendListEntity;
import com.zone.sdk.module.comment.entity.SearchResultEntity;
import com.zone.sdk.module.comment.request.AppSearchRequest;
import com.zone.sdk.module.comment.request.CommentDetailRequest;
import com.zone.sdk.module.comment.request.CommentListRequest;
import com.zone.sdk.module.comment.request.CommentScoreRequest;
import com.zone.sdk.module.comment.request.RecommendListRequest;
import com.zone.vehicle.sdk.module.superapp.CloudSuperAppServiceManager;
import com.zone.vehicle.sdk.module.superapp.request.AppsDownloadRequest;
import com.zone.vehicle.sdk.module.superapp.request.SyncStatusRequest;

import java.util.List;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.http.Body;
import retrofit2.http.Part;

public class SuperAppManager {

    public static SuperAppManager instance;

    private final CloudSuperAppServiceManager cloudSuperAppServiceManager;
    private final CloudAccountServiceManager cloudAccountServiceManager;
    private final CloudAppStoreServiceManager cloudAppStoreServiceManager;
    private final CloudCommentServiceManager cloudCommentServiceManager;
//    private final SuperAppVehicleServiceManager superAppVehicleServiceManager;

    public static SuperAppManager getInstance(String baseUrl, boolean mock, Context context, String mockFileName) {
        if(instance == null){
            instance = new SuperAppManager(baseUrl, mock, context, mockFileName);
            return instance;
        }
        return instance;
    }

    private SuperAppManager(String baseUrl, boolean mock, Context context, String mockFileName){
//        OkHttpManager.getInstance().init(baseUrl);
        if (mock){
            ApiMock.init(mock, context, mockFileName);
        }
        cloudSuperAppServiceManager = CloudSuperAppServiceManager.getInstance("http://acp.z-onesoftware.com/");
        cloudAccountServiceManager = CloudAccountServiceManager.getInstance(baseUrl);
        cloudAccountServiceManager.setAuthorization("cloudAccountService");
        cloudAppStoreServiceManager = CloudAppStoreServiceManager.getInstance("http://acp.z-onesoftware.com/");
        cloudCommentServiceManager = CloudCommentServiceManager.getInstance("http://acp.z-onesoftware.com/");
//        superAppVehicleServiceManager = SuperAppVehicleServiceManager.getInstance();
//        cloudSuperAppServiceManager.init(baseUrl);
    }

    public void setHeader(String key, String value){
        cloudAccountServiceManager.setHeader(key, value);
    }

    /*************************************AppStore********************************************/

    /**
     * 首页list
     */
    public void homeAppList(BaseRequest request, ResultCallBack<Result<AppStoreResult<AppEntity>>> callback){
        cloudAppStoreServiceManager.homeAppList(request, callback);
    }

    /**
     * 应用详情
     */
    public void appsDetail(AppsDetailRequest request, ResultCallBack<Result<AppEntity>> callback){
        cloudAppStoreServiceManager.appsDetail(request, callback);
    }

    /**
     * 应用详情
     */
    public void appList(AppsDetailRequest request, ResultCallBack<Result<List<AppEntity>>> callback){
        cloudAppStoreServiceManager.appList(request, callback);
    }

    /*********************************************************************************/

    /**********************************搜索、评论模块*********************************************/

//    /**
//     * 安利墙列表
//     */
//    public void recommendList(RecommendListRequest request, ResultCallBack<Result<PageResult<RecommendEntity>>> callback){
//        cloudCommentServiceManager.recommendList(request, callback);
//    }

    /*********************************************************************************/
    /**
     * 车机端同步下载队列应用并由云端推送到手机端
     *
     */
    public void indexSearch(AppSearchRequest request, ResultCallBack<Result<CommentPage<SearchResultEntity>>> callback){
        cloudCommentServiceManager.indexSearch(request, callback);
    }

    /**
     * 显示app总体评分和所有用户评价列表
     */
    public void commentScore(CommentScoreRequest request, ResultCallBack<Result<AppCommentScoreEntity>> callback){
        cloudCommentServiceManager.commentScore(request, callback);
    }

    /**
     * 显示app总体评分和所有用户评价列表
     */
    public void commentCommentList(CommentListRequest request, ResultCallBack<Result<CommentListEntity>> callback){
        cloudCommentServiceManager.commentCommentList(request, callback);
    }

    /**
     * 显示app总体评分和所有用户评价列表
     */
    public void commentCommentDetail(CommentDetailRequest request, ResultCallBack<Result> callback){
        cloudCommentServiceManager.commentCommentDetail(request, callback);
    }
//
//    public void appList(AppListRequest request, ResultCallBack<Result> callback){
//        cloudSuperAppServiceManager.appList(request, callback);
//    }
//
    /**
     * 应用状态同步
     */
    public void syncStatus(SyncStatusRequest request, ResultCallBack<Result> callback){
        cloudSuperAppServiceManager.syncStatus(request, callback);
    }
//
//    /**
//     * 应用更新列表查询
//     */
//    public void appsUpdateList(AppsUpdateListRequest request, ResultCallBack<Result> callback){
//        cloudSuperAppServiceManager.appsUpdateList(request, callback);
//    }
//
//    /**
//     * 用户信息查询
//     */
//    public void user(UserRequest request, ResultCallBack<Result> callback){
//        cloudSuperAppServiceManager.user(request, callback);
//    }

    /**
     * 应用更新列表查询
     */
    public void appsDownload(AppsDownloadRequest request, ResultCallBack<ResponseBody> callback){
        cloudSuperAppServiceManager.appsDownload(request, callback);
    }
//
//    /**
//     * 开发者通过此接口将小程序的白名单同步到
//     * appStore
//     */
//    public void appsSyncAbilityList(AppsSyncAbilityListRequest request, ResultCallBack<Result> callback){
//        cloudSuperAppServiceManager.appsSyncAbilityList(request, callback);
//    }
//
//    /**
//     * 车机端同步下载队列应用并由云端推送到手机端
//     */
//    public void appsDownloadQueue(AppsDownloadQueueRequest request, ResultCallBack<Result> callback){
//        cloudSuperAppServiceManager.appsDownloadQueue(request, callback);
//    }
//
//    /**
//     * 文件上传（图片）
//     */
//    public void appsUpload(AppsUploadRequest request, ResultCallBack<Result> callback){
//        cloudSuperAppServiceManager.appsUpload(request, callback);
//    }

    /**
     * 下载用户对app进行评价及安利
     */
    public void commentEditComment(BaseRequest request, ResultCallBack<Result> callback){
        cloudCommentServiceManager.commentEditComment(request, callback);
    }

    /**
     * 下载用户对app下的用户评论进行回复
     */
    public void commentEditReply(BaseRequest request, ResultCallBack<Result> callback){
        cloudCommentServiceManager.commentEditReply(request, callback);
    }

    /**
     * 对用户的评论进行点赞
     */
    public void commentCommentPraise(BaseRequest request, ResultCallBack<Result> callback){
        cloudCommentServiceManager.commentCommentPraise(request, callback);
    }

    /**
     * 用户评论审核不通过，可对当前评论进行修改
     */
    public void commentInitCommentDetail(BaseRequest request, ResultCallBack<Result> callback){
        cloudCommentServiceManager.commentInitCommentDetail(request, callback);
    }

    /**
     * 用户评论审核不通过，可对当前评论进行修改
     */
    public void commentUpdateComment(BaseRequest request, ResultCallBack<Result> callback){
        cloudCommentServiceManager.commentUpdateComment(request, callback);
    }

    /**
     * 分页显示安利墙列表
     *
     *
     */
    public void commentInitAmwayWallList(RecommendListRequest request, ResultCallBack<Result<RecommendListEntity>> callback){
        cloudCommentServiceManager.commentInitAmwayWallList(request, callback);
    }

    /**
     * 用户查看自己评论过的信息列表
     *
     *
     */
    public void commentUserCommentList(CommentListRequest request, ResultCallBack<Result<CommentListEntity>> callback){
        cloudCommentServiceManager.commentUserCommentList(request, callback);
    }

    /**
     * 用户删除自己的评论
     *
     *
     */
    public void commentDelUserComment(BaseRequest request, ResultCallBack<Result> callback){
        cloudCommentServiceManager.commentDelUserComment(request, callback);
    }

    /**
     * 查询应用下评论数，不包含回复和回复回复
     *
     *
     */
    public void commentSearchCommentCount(BaseRequest request, ResultCallBack<Result> callback){
        cloudCommentServiceManager.commentSearchCommentCount(request, callback);
    }

    /**
     * 用户提交意见反馈
     */
    public void feedbackFeedbackCommit(BaseRequest request, ResultCallBack<Result> callback){
        cloudCommentServiceManager.feedbackFeedbackCommit(request, callback);
    }

    /*******************************账号****************************************/

    public void captchaGet(CaptchaGetRequest request, ResultCallBack<CaptchaGetResponse<CaptchaGetEntity>> callback){
        cloudAccountServiceManager.captchaGet(request, callback);
    }

    public void checkCaptcha(CheckCaptchaRequest request, ResultCallBack<CaptchaGetResponse<CheckCaptchaEntity>> callback){
        cloudAccountServiceManager.checkCaptcha(request, callback);
    }

    /**
     * 车机端同步下载队列应用并由云端推送到手机端
     * /user/captchacert/exchange/v1
     */
    public void captchacertExchange(CaptchaCertExchangeRequest request, ResultCallBack<Result<CaptchaCertExchangeEntity>> callback){
        cloudAccountServiceManager.captchacertExchange(request, callback);
    }

    /**
     * 手机号+验证码登录/注册/忘记密码流程中，调用此接口获取短信验证码
     */
    public void loginPhoneCode(LoginRequest request, ResultCallBack<Result<LoginEntity>> callback){
        cloudAccountServiceManager.loginPhoneCode(request, callback);
    }

    /**
     * 手机号+验证码登录/注册/忘记密码流程中，调用此接口获取短信验证码
     * 与获取验证码接口相同，请求参数做区分 loginPhoneCode
     */
    public void loginPhoneCodeCheck(LoginRequest request, ResultCallBack<Result<LoginEntity>> callback){
        cloudAccountServiceManager.loginPhoneCodeCheck(request, callback);
    }

    /**
     * 手机号+密码登录流程中，调用此接口提交登录请求，并获取登录信息
     *
     *
     */
    public void loginPhonePwd(LoginRequest request, ResultCallBack<Result<LoginEntity>> callback){
        cloudAccountServiceManager.loginPhonePwd(request, callback);
    }

    /**
     * 用户持有有效Access Token 状态下，调用此接口设置密码。
     *
     *
     */
    public void userPwdModify(LoginRequest request, ResultCallBack<Result> callback){
        cloudAccountServiceManager.userPwdModify(request, callback);
    }

    /**
     * 用户持有有效Access Token 状态下，调用此接口获取个人基本信息
     *
     *
     */
    public void queryUserInfo(ResultCallBack<Result<UserInfoEntity>> callback){
        cloudAccountServiceManager.queryUserInfo(callback);
    }

    /**
     * 用户持有有效Access Token 状态下，调用此接口修改个人基本信息。
     *
     *
     */
    public void updateUserInfo(UserInfoRequest request, ResultCallBack<Result> callback){
        cloudAccountServiceManager.updateUserInfo(request, callback);
    }

    /**
     * 用户持有有效Access Token 状态下，调用此接口退出当前账号
     *
     *
     */
    public void logout(LogoutRequest request, ResultCallBack<Result> callback){
        cloudAccountServiceManager.logout(request, callback);
    }

    /**
     * 用户Access Token 过期状态下，调用此接口以获取新的Token。
     *
     *
     */
    public void refreshToken(RefreshTokenRequest request, ResultCallBack<Result<LoginEntity>> callback){
        cloudAccountServiceManager.refreshToken(request, callback);
    }

    /**
     * 用户持有有效Access Token 状态下，调用此接口上传文件（移动端用于上传自定义头像）。
     *
     *
     */
    public void userUpload(@Part("files") RequestBody body, @Body UploadRequest request, ResultCallBack<Result<UploadEntity>> callback){
        cloudAccountServiceManager.userUpload(body, request, callback);
    }

    /**
     * 用户持有有效Access Token 状态下，调用此接口查询当前账户在所有设备上的登录状态
     *
     *
     */
    public void loginStatus(ResultCallBack<Result<LoginStatusEntity>> callback){
        cloudAccountServiceManager.loginStatus(callback);
    }

    /**
     * 车机端调用此接口生成登录二维码，返回的是QR Code URL
     *
     *
     */
    public void qrLoginCode(QrLoginRequest request, ResultCallBack<Result<QrLoginEntity>> callback){
        cloudAccountServiceManager.qrLoginCode(request, callback);
    }

    /**
     * 车机端通过此接口轮询登录状态。
     *
     *
     */
    public void qrLoginCodeStatus(QrLoginPollRequest request, ResultCallBack<Result<QrLoginPollEntity>> callback){
        cloudAccountServiceManager.qrLoginCodeStatus(request, callback);
    }
    /*******************************账号 end****************************************/

}
